<template>
	<view>
		<view style="margin-bottom: 20rpx; ">
			<u-search v-model="query.ta016" placeholder='收款人(单位)' @custom="search" @search='search'></u-search>
			<u-search v-model="query.ta017" placeholder='开户行' @custom="search" @search='search'></u-search>
			<u-search v-model="query.ta018" placeholder='银行账户' @custom="search" @search='search'></u-search>
			<view style="margin: 10rpx;">
				<u-button type="warning" plain @click="Reset">重置</u-button>
			</view>
		</view>
		<uni-table ref="table" :loading="loading" border stripe type="selection" emptyText="暂无更多数据"
			@selection-change="selectionChange">
			<uni-tr>
				<uni-th align="center">收款人</uni-th>
				<uni-th align="center">开户行</uni-th>
				<uni-th align="center">银行账户</uni-th>
			</uni-tr>
			<uni-tr v-for="(item, index) in tableData" :key="index">
				<uni-td align="center">{{ item.ta016 }}</uni-td>
				<uni-td align="center">{{ item.ta017 }}</uni-td>
				<uni-td align="center">{{ item.ta018 }}</uni-td>
			</uni-tr>
		</uni-table>

		<view style="margin: 10rpx ;">
			<uni-pagination show-icon :page-size="query.pageSize" :current="query.currentPage" :total="total"
				@change="change" />
		</view>
		<u-button type="primary" @click="submit">确认</u-button>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		getPersonBankInfo
	} from "@/api/workFlow/flowBefore";
	export default {
		data() {
			return {
				tableData: [],
				total: 0,
				loading: false,
				query: {
					ta016: null,
					ta017: null,
					ta018: null,
					pageSize: 10,
					currentPage: 1,
					sort: 'asc',
					sidx: null
				}
			};
		},
		onShow() {
			this.getData()
		},
		methods: {
			Reset() {
				this.query = {
					ta016: null,
					ta017: null,
					ta018: null,
					pageSize: 10,
					currentPage: 1,
					sort: 'asc',
					sidx: null
				}
				this.getData()
			},
			search() {
				this.getData()
			},
			// 多选
			selectionChange(e) {
				this.selectedIndexs = e.detail.index
				if (this.selectedIndexs.length > 1) {
					return this.$refs.uToast.show({
						title: "只能选择一条数据",
						type: "error",
					});
				}
			},
			// 分页触发
			change(e) {
				this.$refs.table.clearSelection()
				this.selectedIndexs.length = 0
				this.query.currentPage = e.current
				this.getData()
			},
			// 搜索
			search() {
				this.getData(1, this.query)
			},
			// 获取数据
			getData() {
				this.loading = true
				getPersonBankInfo(this.query).then(res => {
					console.log('data', res);
					this.tableData = res.data.list
					this.total = res.data.pagination.total
					this.loading = false
				})

			},
			submit() {
				if (this.selectedIndexs.length > 1) {
					return this.$refs.uToast.show({
						title: "只能选择一条数据",
						type: "error",
					});
				}
				uni.showModal({
					title: "提示",
					content: `您确定选择当前收款人/单位吗？`,
					success: (res) => {
						if (res.confirm) {
							this.selfHandleRequest();
						}
					},
				});
			},
			selfHandleRequest() {
				uni.showToast({
					title: '操作成功',
					complete: () => {
						setTimeout(() => {
							uni.$emit("updateta016", this.tableData[this.selectedIndexs[0]]);
							uni.navigateBack();
						}, 1500);
					},
				});
			}


		},
	};
</script>